﻿namespace Blaze.Framework.LuaExtensions.FileLoaders
{
    /// <summary>
    /// 配置文件重定向Lua文件加载器。
    /// </summary>
    public class ConfigRedirector
    {
        public ConfigRedirector(string rootPath)
        {
            mInternalLoader = new FromDirectory(rootPath);
        }

        public byte[] ReadFile(ref string filePath)
        {
            if (!filePath.StartsWith("configs."))
                return null;

            var redirection = filePath.Substring("configs.".Length);
            var ret = mInternalLoader.ReadFile(ref redirection);
            if (ret == null)
                return null;
            filePath = redirection;
            return ret;
        }

        private readonly FromDirectory mInternalLoader;
    }
}